package com.lincoln.cartoon.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class StaticResourcesConfigurer extends WebMvcConfigurationSupport {
    @Autowired
    AllHandlerInterceptor allHandlerInterceptor;

    @Bean
    public AllHandlerInterceptor allHandlerInterceptor() {
        return new AllHandlerInterceptor();
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(allHandlerInterceptor).addPathPatterns("/**");
        super.addInterceptors(registry);
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        if (System.getProperty("os.name").toLowerCase().contains("windows")) {
            registry.addResourceHandler("/img/**").addResourceLocations("file:D:/mh/");
        } else if (System.getProperty("os.name").toLowerCase().contains("linux")) {
            registry.addResourceHandler("/img/**").addResourceLocations("file:/mh/");
        }
        super.addResourceHandlers(registry);
    }
}
